/*
 *  Copyright 2005 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.common.util;

import java.io.Serializable;

/**
 * <p>Contains some object along with some numbers ('total count' and
 * 'unique count').</p>
 * <p><a href="ObjectCountInfo.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.3 $ $Date: 2006/06/03 16:32:28 $
 */
public class ObjectCountInfo implements Serializable, Comparable {

    /**
     * Object
     */
    protected Object object;

    /**
     * Total count
     */
    protected Integer totalCount;

    /**
     * Unique count
     */
    protected Integer uniqueCount;

    /**
     * Default constructor.
     */
    public ObjectCountInfo() {
        object = null;
        totalCount = null;
        uniqueCount = null;
    }

    /**
     * Constructs an ObjectCountInfo instance specifying object and counts.
     *
     * @param object object
     * @param totalCount total count
     * @param uniqueCount unique count
     */
    public ObjectCountInfo(Object object, Integer totalCount, Integer uniqueCount) {
        this.object = object;
        this.totalCount = totalCount;
        this.uniqueCount = uniqueCount;
    }

    /**
     * Returns object.
     *
     * @return object
     */
    public Object getObject() {
        return object;
    }

    /**
     * Sets object.
     *
     * @param object object to set
     */
    public void setObject(Object object) {
        this.object = object;
    }

    /**
     * Returns total count.
     *
     * @return total count
     */
    public Integer getTotalCount() {
        return totalCount;
    }

    /**
     * Sets total count.
     *
     * @param totalCount count to set
     */
    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    /**
     * Returns unique count.
     *
     * @return unique count
     */
    public Integer getUniqueCount() {
        return uniqueCount;
    }

    /**
     * Sets unique count.
     *
     * @param uniqueCount count to set
     */
    public void setUniqueCount(Integer uniqueCount) {
        this.uniqueCount = uniqueCount;
    }

    /**
     * Increases counts.
     *
     * @param total value to add to total count
     * @param unique value to add to unique count
     */
    public void increaseCounts(Integer total, Integer unique) {
        totalCount = new Integer(totalCount.intValue() + total.intValue());
        uniqueCount = new Integer(uniqueCount.intValue() + unique.intValue());
    }

    /**
     * <p>Compares this object with the specified object for order. Returns a
     * negative integer, zero, or a positive integer as this object is less
     * than, equal to, or greater than the specified object.</p>
     * <p>Comparation is made firstly on unique count, then on total count.
     * </p>
     * <p>Comparation is made in reverse order (from most to least).
     * </p>
     *
     * @param o the Object to be compared.
     * @return a negative integer, zero, or a positive integer as this object
     *         is less than, equal to, or greater than the specified object.
     * @throws ClassCastException if the specified object's type prevents it
     *                            from being compared to this Object.
     */
    public int compareTo(Object o) {
        ObjectCountInfo info = (ObjectCountInfo) o;
        if (this.getUniqueCount().equals(info.getUniqueCount())) {
            return -this.getTotalCount().compareTo(info.getTotalCount());
        } else {
            return -this.getUniqueCount().compareTo(info.getUniqueCount());
        }
    }
}
